package com.hjl.filter; /**
 * @author ServivE
 * @className ${NAME}
 * @description ${description}
 * @version 0.1
 * @date 2024/7/30 10:29
 * @since jdk11
 */

import javax.servlet.*;
import javax.servlet.annotation.*;
import java.beans.Encoder;
import java.io.IOException;
import java.net.URLEncoder;

@WebFilter(filterName = "EncodingFilter", value = "/*")
public class EncodingFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        //统一处理请求和响应的乱码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        chain.doFilter(request, response);
    }
}
